﻿
Partial Class Administracion_Clave
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            cargarUsuario()
        End If
    End Sub
    Sub cargarUsuario()
        Dim u As New Web_Usuario
        Dim h As New Helper
        u = h.GetUsuario(Context.User.Identity.Name)
        lblUsuario.Text = u.Nombres & " " & u.Apellidos
        hdIdUsuario.Value = u.IdUsurio
    End Sub

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        Dim bd As New bdSeguridadDataContext
        Dim a = From u In bd.Web_Usuarios
                 Where u.Clave = txtpwlActual.Text And u.Usuario = Context.User.Identity.Name
                 Select u
        If a.Count = 0 Then
            args.IsValid = False
        End If
    End Sub

    Protected Sub txtBotonGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBotonGuardar.Click
        If Page.IsValid = False Then
            Exit Sub
        End If
        Using bd As New bdSeguridadDataContext
            Dim a = bd.Web_SP_ActualizarClave(CInt(hdIdUsuario.Value), txtClave.Text)
            bd.registrarLog(Context.User.Identity.Name, 9, Request.CurrentExecutionFilePath)
        End Using
        Dim script = "alert('Se ha actualizado la clave');"

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Abrir", script, True)


    End Sub
End Class
